package com.maccman.aireo.command
{
	/* add to controller
	addCommand( GetAssetsEvent.EVENT_GET_ASSETS, GetAssetsCommand );
	*/
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.commands.ICommand;

	import com.maccman.aireo.model.AireoModelLocator;
	import com.maccman.aireo.control.GetAssetsEvent;

	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	
	import com.maccman.activeresource.ActiveResource;
	import com.maccman.activeresource.models.Asset;
	import com.maccman.activeresource.IndexedCollection;
	import mx.collections.ArrayCollection;
	import mx.utils.ArrayUtil;
	import mx.rpc.xml.SimpleXMLDecoder;
	import flash.xml.XMLNode;
	
	import com.maccman.aireo.vo.AssetVO;

	public class GetAssetsCommand implements ICommand, IResponder
	{
		public function execute(event:CairngormEvent):void
		{
		    var delegate : Asset = new Asset( this )
		    delegate.find_all();
		}
		
		public function result(data:Object):void
		{
		  var model = AireoModelLocator.getInstance()
		  var myArray:Array = new Array;
		    for each(var i:XML in data.asset) {
		       var o:AssetVO = new AssetVO;
		       for( var s:int=0; s< i.children().length() ;s++){
		       	if( o.hasOwnProperty(i.children()[s].localName()) ) {
		       	 o[i.children()[s].localName()] = i.children()[s].toString()
		       	}
		       }
               myArray.push(o);
        	}
		  model.assets = new IndexedCollection(myArray,'id')
		}
		
		
		public function fault(info:Object):void
		{
			var faultEvent :FaultEvent = FaultEvent( info )
			Alert.show( "fault at getAssets" )
		}
		
	}
}